package com.yoomiito.app.adapter.address

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.isVisible
import com.yoomiito.app.model.bean.AddressInfo
import com.yoomiito.app.utils.ColorUtils
import com.yoomiito.app.widget.NoClickLinearLayout
import com.yoomiito.app.widget.SelectView

class AddressAdapter(data:List<AddressInfo>?) :BaseQuickAdapter<AddressInfo,BaseViewHolder>(R.layout.item_address_1,data){

    override fun convert(helper: BaseViewHolder?, item: AddressInfo?) {
        helper?.addOnClickListener(R.id.selectAddressView)
        helper?.addOnClickListener(R.id.editAddressTv)
        helper?.getView<NoClickLinearLayout>(R.id.selectAddressView)?.isEnabled = item?.isShowCheckBox!!
        helper?.setGone(R.id.addressSelect,item?.isShowCheckBox!!)
        helper?.getView<SelectView>(R.id.addressSelect)?.setSelect(item?.select=="1")
//        val name = if (item?.isShowCheckBox) if(item?.userName.length>3) "${item?.userName.substring(0,3)}..." else item?.userName else item?.userName
        val nameTv = helper?.getView<TextView>(R.id.nameTv)
        nameTv?.text = item?.userName
        nameTv?.requestLayout()
//        helper?.setText(R.id.nameTv,)
        helper?.setText(R.id.telTv,item?.mobile)
        val defaultFlag = helper?.getView<TextView>(R.id.defaultAddressFlag)
        defaultFlag?.isVisible(item?.isDefault=="1")
        defaultFlag?.background = ColorUtils.background(R.color.color_1AFF035B,4f)
        helper?.setText(R.id.addressDetailTv,item?.provinceName+item?.cityName+item?.countyName+item?.address)
    }

}